package com.itheima.File文件.file练习;

import java.io.File;
import java.util.HashMap;

public class 统计文件类型次数 {
    public static void main(String[] args) {
        File file = new File("day10可变参数和Stream流");
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        getCount(file, map);
        map.entrySet().forEach(entry -> System.out.println(entry.getKey() + "..." + entry.getValue()));

    }

    private static void getCount(File file, HashMap<String, Integer> map) {
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isFile()) {
                String name = file1.getName();
                String[] ss = name.split("\\.");
                if (ss.length == 2) {
                    String firstname = ss[1];
                    if (map.containsKey(firstname)) {
                        int count = map.get(firstname);
                        count++;
                        map.put(firstname, count);
                    } else {
                        map.put(firstname, 1);
                    }
                }
            } else {
                getCount(file1, map);
            }
        }
    }
}
